#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
void RunChild()
{
    int cnt=5;
    while(cnt)
    {
        printf("I am child proc,pid:%d,ppid:%d\n",getpid(),getppid());
        sleep(1);
        cnt--;
    }
}
int main()
{
    printf("I am parent proc,pid:%d,ppid:%d\n",getpid(),getppid());
    sleep(2);
    pid_t id=fork();
    if(id==0)
    {
        RunChild();
        exit(1);
        printf("Child quit.....\n");
    }
    sleep(10);
    int status=0;

    //pid_t rid=wait(NULL);
    pid_t rid=waitpid(-1,&status,0);

    if(rid>0)
    {
        printf("Wait success......\n");
    }
    sleep(3);
    printf("parent quit.....\n");
    printf("father quit,ststus:%d,child return code:%d,child return signal:%d\n",status,(status>>8)&0xFF,status&0x7F);

    return 0;
}
